﻿using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using GHI.Premium.Net;

namespace STOMP
{
    public partial class Program
    {
        //reference of OSC module.
        STOMP stomp;

        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            //SETUP NETWORKING
            Debug.Print("Program Started");
            ethernet_J11D.Interface.Open();
            NetworkInterfaceExtension.AssignNetworkingStackTo(ethernet_J11D.Interface);
            ethernet_J11D.Interface.NetworkInterface.EnableDhcp();
            ethernet_J11D.Interface.NetworkAddressChanged += new GHI.Premium.Net.NetworkInterfaceExtension.NetworkAddressChangedEventHandler(Interface_NetworkAddressChanged);
        }

        void Interface_NetworkAddressChanged(object sender, EventArgs e)
        {
            //print our IP address
            Debug.Print("Address: " + ethernet_J11D.Interface.NetworkInterface.IPAddress);

            //Create a new OSC module.
            stomp = new STOMP();
            //stomp.Connect("10.67.33.62", 61613);
            stomp.Connect("128.240.66.39", 80);
            //var sub1 = stomp.Subscribe("/topic/Kitchen/RfidLabels");
            //sub1.MessageReceived += new STOMP.STOMPMessageEventHandler(sub1_MessageReceived);
        }

        void sub1_MessageReceived(STOMP sender, string address, string message)
        {
            Debug.Print(message);
        }
    }
}
